package com.hdax.dm.controller;

import com.hdax.dm.Vo.EsQuerygoodsinfosVo;
import com.hdax.dm.dto.*;
import com.hdax.dm.service.EsService;
import com.hdax.dm.service.ItemService;
import com.hdax.dm.utils.response.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/item/list")
public class ESController {


    @Autowired
    private EsService esService;

    @Autowired
    private ItemService itemService;

    // 列表页 2. 查询分类接口
    @PostMapping("sortgoods")
    public CommonResponse<List<SortgoodsDto>> sortgoods(@RequestBody Map<String,Integer> map){
        return esService.sortgoods(map.get("parent")!=null?0:map.get("param"));
    }

    // 3. 根据城市、一级分类、二级分类查询商品信息
    @PostMapping("querygoodsinfos")
    public CommonResponse<EsItemDto> querygoodsinfos(@RequestBody EsQuerygoodsinfosVo vo) throws IOException {
        return esService.querygoodsinfos(vo);
    }
    // 列表页 2. 查询分类接口
    @PostMapping("guesslike")
    public CommonResponse<List<ItemCinemaDto>> guesslike(@RequestBody Map<String,Integer> map){
        return itemService.guesslike(map.get("itemTypeId"));
    }
}
